# Process this file with autoconf to produce a configure script.

AC_INIT([OpenStereo Library], [1.0.0], [openstereo-dev@googlegroups.com], [openstereo])
AM_INIT_AUTOMAKE([-Wall -Werror])
AC_CONFIG_SRCDIR([AUTHORS])
AC_CONFIG_HEADERS([config.h])

AM_MAINTAINER_MODE

# Checks for programs.
AC_PROG_CC
AM_DISABLE_STATIC
AC_PROG_LIBTOOL

# Checks for libraries.

# Checks for header files.

PKG_CHECK_MODULES(GLIB, glib-2.0)
PKG_CHECK_MODULES(GMODULE, gmodule-2.0)

# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.

# Build time configuration.

openstereoplugindir=$libdir/plugins
AC_SUBST(openstereoplugindir)

#if PLATFORM_WIN32
#no_undefined = -no-undefined
#endif

AC_SUBST(PLUGIN_FLAGS, "-shared -avoid-version $no_undefined")

AC_ARG_ENABLE([build-plugins], [AS_HELP_STRING([--enable-build-plugins],
	[build bundled plugins @<:@default=yes@:>@])], [build_plugins=yes])
if test "x$enable_build_plugins" != xno; then
	AC_MSG_CHECKING([whether we have OpenGL headers])
	AC_CHECK_HEADERS([GL/gl.h GL/glu.h], , [AC_MSG_ERROR([Could not find OpenGL headers.])])

	AC_MSG_CHECKING([whether we have OpenGL libraries])
	AC_CHECK_LIB([GL], [glReadPixels], [GL_LDFLAGS="$GL_LDFLAGS -lGL"],
		[AC_MSG_ERROR([Could not find OpenGL library.])])

	AC_CHECK_LIB([GLU], [gluLookAt], [GL_LDFLAGS="$GL_LDFLAGS -lGLU"],
		[AC_MSG_ERROR([Could not find OpenGL Utility library.])])

	AC_SUBST([GL_LDFLAGS])

	AC_MSG_CHECKING([whether we have GLEW headers])
	AC_CHECK_HEADERS([GL/glew.h], , [AC_MSG_ERROR([Could not find GLEW headers.])])

	AC_MSG_CHECKING([whether we have GLEW library])
	AC_CHECK_LIB([GLEW], [glewInit], [GLEW_LDFLAGS="$GLEW_LDFLAGS -lGLEW"],
		[AC_MSG_ERROR([Could not find GLEW library.])])

	AC_SUBST([GLEW_LDFLAGS])

	AC_MSG_CHECKING([whether we have Cg headers])
	AC_CHECK_HEADERS([Cg/cg.h Cg/cgGL.h], , [AC_MSG_ERROR([Could not find Cg headers.])])
	
	AC_MSG_CHECKING([whether we have Cg libraries and dependencies])

	AC_CHECK_LIB([Cg], [cgCreateContext], [CG_LDFLAGS="$CG_LDFLAGS -lCg"],
		[AC_MSG_ERROR([Could not find Cg library.])], [-lm -lGL])

	AC_CHECK_LIB([CgGL], [cgGLLoadProgram], [CG_LDFLAGS="$CG_LDFLAGS -lCgGL"],
		[AC_MSG_ERROR([Could not find Cg OpenGL library.])], [-lm -lCg -lGL])

	AC_SUBST([CG_LDFLAGS])
	
fi

AM_CONDITIONAL([BUILD_PLUGINS], [test "x$enable_build_plugins" != xno])

# Configures headers and files
AC_CONFIG_FILES([Makefile include/Makefile include/SL/Makefile plugins/Makefile
	src/Makefile scripts/Makefile])

# Outputs everything
AC_OUTPUT

